#define  _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <thread>
#include <mutex>
#include <condition_variable>
std::condition_variable cond;
std::mutex mutex;


int main()
{
	int cnt = 0;
	bool flag = false;
	std::thread t1([&](){
		while (true)
		{
			std::unique_lock<std::mutex> ul(mutex);
			cond.wait(ul, [&]() {return !flag; });
			if (cnt >= 10)
			{
				flag = true;
				cond.notify_one();
				break;
			}
			std::cout << "thread-1 : " << cnt++ << std::endl;
			flag = true;
			cond.notify_one();
		}
	});
	std::thread t2([&]() {
		while (true)
		{
			std::unique_lock<std::mutex> ul(mutex);
			cond.wait(ul, [&]() {return flag; });
			if (cnt >= 10)
			{
				flag = false;
				cond.notify_one();
				break;
			}
			std::cout << "thread-2 : " << cnt++ << std::endl;
			flag = false;
			cond.notify_one();
		}
	});
	t1.join();
	t2.join();
	return 0;
}